/*
 * @Description:
 * @Version:
 * @Autor: 李石
 * @Date: 2023-12-19 07:32:19
 * @LastEditors: error: git config user.name & please set dead value or install git
 * @LastEditTime: 2024-05-19 18:12:00
 */
#ifndef _SYS_PARAMS_HPP_
#define _SYS_PARAMS_HPP_
#include <iostream>
#include <memory>
#include <mutex>
#include "StreamDto.hpp"

class SysParams {
public:
    SysParams(const SysParams&) = delete;
    SysParams& operator=(const SysParams&) = delete;
    ~SysParams();
    bool load();
    bool save() const;
    bool insert_stream(const std::string &app, const std::string &stream, const std::string &url, int rtp_type, std::string &err);
    bool update_stream(const std::string &app, const std::string &stream, const int codec, bool alive, const std::string &play);
    bool remove_stream(const std::string &app, const std::string &stream, std::string &err);
    StreamReportDto::Ptr get_stream(const std::string &app, const std::string &stream, std::string &err) const;
    StreamListDto::Ptr get_stream(std::string &err) const;
    static SysParams* getInstance(const std::string& config_path_ = std::string("config.json"));

private:
    SysParams(const std::string& config_path_);
    bool setToDefaultConf();

private:
    mutable std::mutex mutex_;
    std::string m_config_path_;
    StreamsInfoDto::Ptr streams_info_;
    static std::unique_ptr<SysParams> instance;
    static std::mutex SingleMutex;
};

#endif  // _SYS_PARAMS_HPP_